package endpoint

import (
	"context"
	"github.com/go-kit/kit/endpoint"
	"google.golang.org/genproto/googleapis/ads/googleads/v1/errors"
	"test/service"
)

type UppercaseRequest struct {
	S string `json:"s"`
}
type UppercaseResponse struct {
	V   string `json:"v"`
	Err string `json:"err,omitempty"`
}
type CountRequest struct {
	S string `json:"s"`
}
type CountResponse struct {
	V int `json:"v"`
}

func makeUpperEndPoint(svc service.StringService) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(UppercaseRequest)
		v, err := svc.Uppercase(req.S)
		if err != nil {
			return UppercaseResponse{v, err.Error()}, nil
		}
		return UppercaseResponse{v, ""}, nil
	}
}

func makeCountEndpoint(svc service.StringService) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(CountRequest)
		v := svc.Count(req.S)
		return v, nil
	}

}
